package Q3;

import java.util.Scanner;

public class Main {

    public static int n;
    public static int k;
    public static int[] arr;
    public static int ret;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        n = scanner.nextInt();
        k = scanner.nextInt();
        arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }

        dfs(0, 0);

        System.out.println(ret == 0 ? -1 : ret);
    }

    public static void dfs(int index, int sum) {
        if (sum % k == 0) {
            ret = Math.max(ret, sum);
        }

        if (index == n) {
            return;
        }

        //选
        dfs(index + 1, sum + arr[index]);

        //不选
        dfs(index + 1, sum);
    }
}
